﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InputMgr : BaseManager<InputMgr>
{

    private bool isStart = false;
    //构造函数中设定自己的Update方法
    public InputMgr()
    {
        MonoManager.GetInstance().AddUpdateListener(MyUpdate);
    }
    /// <summary>
    /// 设定输入检测是否启用的方法
    /// </summary>
    /// <param name="isOpen"></param>
    public void StartOrEndCheck(bool isOpen)
    {
        isStart = isOpen;
    }
    /// <summary>
    /// 发布按下和抬起事件的方法
    /// </summary>
    /// <param name="key">按键名</param>
    private void CheckKey(KeyCode key)
    {
        if (Input.GetKeyDown(key))
        {
            EventCenter.GetInstance().EventTrigger("某键按下",key);
        }
        if (Input.GetKeyUp(key))
        {
            EventCenter.GetInstance().EventTrigger("某键抬起", key);
        }
        
    }
    /// <summary>
    /// 统一设定要发布事件的按键
    /// </summary>
    public void MyUpdate()
    {
        if (!isStart)
        {
            return;
        }
        CheckKey(KeyCode.W);
        CheckKey(KeyCode.A);
        CheckKey(KeyCode.S);
        CheckKey(KeyCode.D);
    }
}
